package com.study.test.common;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

@ControllerAdvice(annotations = Controller.class)
@Slf4j
public class GlobalExceptionHandler {
    @ExceptionHandler(MyException.class)
    public String exceptionHandler(MyException ex){

        log.error(ex.getMessage());
        return ex.getMessage();
    }

    @ExceptionHandler(value = {NullPointerException.class})
    public String exceptionHandler(NullPointerException ex){
        log.error("发生了空指针异常啦");
        return  ex.getMessage();
    }


}

